package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.Notice;
import com.zhuojy.equity.mall.admin.dal.mapper.NoticeMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
@RequiredArgsConstructor
public class NoticeService extends ServiceImpl<NoticeMapper,Notice> {
    //分页查询
    public IPage queryNotice(Notice notice) {
       IPage page = new Page<>(notice.getCurrentPage(), notice.getPageSize());
        page = this.baseMapper.queryNotice(page,notice);
       return page;
    }
    /**
     * 删除
     * @param id
     */
    public void deleteNotice(Integer id) {
        this.baseMapper.deleteById(id);
    }

    /**
     * 新增/修改
     * @param notice
     */
    public void addNotice(Notice notice) {
        if(notice.getId()!=null){
            Notice notice1 = new Notice();
            notice1=notice;
            notice1.setUpdateTime(new Date());
            this.baseMapper.updateById(notice1);
        }else {
            notice.setCreationTime(new Date());
            this.baseMapper.insert(notice);
        }
    }
}
